#include <iostream>
#include <string.h>

using std::cout;
using std::endl;

struct Stack{
    size_t cap_;
    char *stk;
    int p;

    Stack():cap_(10), stk(new char[cap_]), p(-1){}

    bool empty() const
    {
        return p == -1;
    }    

    void push(char ch)
    {
        stk[++p] = ch;
    }

    char top()
    {
        if(empty()) 
            throw "stack is empty()!";
        return stk[p];
    }

    void pop()
    {
        if(empty()) 
            throw "stack is empty()!";
        p--;
    }
};

bool isOK(const char *str)
{
    struct Stack stk;

    int size = 0;
    for(;str[size] != '\0';){
        stk.push(str[size++]);
    }
    size++;

    char *ret = (char *)malloc(size * sizeof(char));
    int i = 0;
    while(!stk.empty()){
        ret[i] = stk.top();
        stk.pop();
        i++;
    }
    return strcmp(str, ret) == 0;
}

int main(int args, char *argv[])
{
    cout << std::boolalpha;
    cout << isOK("abba") << endl;
    cout << isOK("abcba") << endl;
    cout << isOK("abc") << endl;
    return 0;
}